﻿using MVC_Project.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MVC_Project.Dal
{
    public class BaseDal<T> where T : class
    {
        public DbContext dbcontext = DbContextFactory.Create();

        public IQueryable<T> Query()
        {
            return dbcontext.Set<T>();
        }

        public void Add(T t)
        {
            dbcontext.Set<T>().Add(t);
        }

        public void Add(List<T> list)
        {
            dbcontext.Set<T>().AddRange(list);
        }

        public void Delete(T t)
        {
            dbcontext.Set<T>().Remove(t);
        }

        public void Delete(List<T> list)
        {
            dbcontext.Set<T>().RemoveRange(list);
        }

        public void Update(T t)
        {
           dbcontext.Set<T>().AddOrUpdate(t);
        }

        public int SaveChanges() {
            return dbcontext.SaveChanges();
        }

    }
}
